<template>
	<el-row>
		<el-col :span="14" :offset="4">
			<el-row>
				<el-col :span="4">
					当前流程：
				</el-col>
				<el-col :span="10">
					{{$route.params.p_name}}
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="24">
					<el-input
						style="overflow-y: scroll;"
						v-model="currentDoc.odContent"
						:rows="15"
						type="textarea"
						placeholder="公文内容..."
						readonly=true
					/>
				</el-col>
				<el-col :span="24">
					<el-input
						style="overflow-y: scroll;"
						v-model="currentDoc.odSuggest"
						:rows="4"
						type="textarea"
						placeholder="请输入审核意见..."
					/>
				</el-col>
				<el-col :span="4">
						<el-select v-model="handleValue" class="m-2" placeholder="公文处理方式" size="default" style="width: 100%;">
							<el-option
							v-for="item in handleStates"
							:key="item.value"
							:label="item.label"
							:value="item.value"
							/>
						</el-select>
				</el-col>
				<el-col :span="3" :offset="17">
					<el-button type="primary" @click = "submitAuditedODoc" style="width: 100%;">
						提交
					</el-button>
				</el-col>
			</el-row>
		</el-col>
		<el-col :span="4" :offset="1">
			<el-card class="box-card">
				<div class="card-header">
					<el-row>
						<el-col :span="24">
							<span>用户名称：</span><span>{{$store.state.account}}</span>
						</el-col>
					</el-row>
				</div>
			</el-card>
		</el-col>
	</el-row>
</template>

<script>

import qs from 'qs'
import {ElMessage} from 'element-plus'
import { ref } from 'vue'
export default{
	data () {
		return {
			currentDoc:{},
			currentProcess:{},
			handleStates:[
					{
						value: '1',
						label: '通过',
					},
					{
						value: '0',
						label: '不通过',
					},
			],
			handleValue:ref('')
		}
	},
	methods:{
		dateFormat(time) {
			var date=new Date(time);
			var year=date.getFullYear();
			/* 在日期格式中，月份是从0开始的，因此要加0
			* 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
			* */
			var month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
			var day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
			var hours=date.getHours()<10 ? "0"+date.getHours() : date.getHours();
			var minutes=date.getMinutes()<10 ? "0"+date.getMinutes() : date.getMinutes();
			var seconds=date.getSeconds()<10 ? "0"+date.getSeconds() : date.getSeconds();
			// 拼接
			return year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
		},
		switchChatObject(tab) {
			console.log(tab.props.name);
		},
		submitAuditedODoc(){
			let that = this
			that.currentDoc.odAuditTime = that.dateFormat(new Date())
			if(that.handleValue==0){
				that.currentDoc.odFlag = 2
				that.currentDoc.odStates = "已驳回"
			}
			else{
				that.currentDoc.odFlag++
				that.currentDoc.odStates = "已通过"//+管理人员职位
			}
			let str = qs.stringify(that.currentDoc)
			this.$axios.get("http://localhost:8080/ODoc/updateODocByOdId?"+str,{
				params:{
					officialdocument:str,
				}
			}).then(function(res){
				if(res.data==true){
					ElMessage({
						message:"提交成功！",
						type:'success',
					})
					that.tabValue="check"
				}else{
					ElMessage.error("提交失败！")
				}
			})
		}
	},
	mounted() {
	//显示当前日期时间
		let _this = this// 声明一个变量指向Vue实例this，保证作用域一致
		this.timer = setInterval(() => {
			_this.date = new Date(); // 修改数据date
		}, 1000)
	},
	beforeUnmount() {
		if (this.timer) {
			clearInterval(this.timer); // 在Vue实例销毁前，清除我们的定时器
		}
	},
	created(){
		let odId = that.$route.params.odId
		let that = this
		//获取当前公文
		this.$axios.get("http://localhost:8080/ODoc/selectODocOneByOdId?odId="+odId).then(function(res){
			console.log(res.data)
			that.currentDoc = res.data
		})
		//获取对应流程
		this.$axios.get("http://localhost:8080/P/selectPByPId?pId="+that.currentDoc.pId).then(function(res){
			console.log(res.data)
			that.currentProcess = res.data
		})
	}
}
</script>